package com.dwxt.sport.controller;

import com.dwxt.common.annotation.ValidateFiled;
import com.dwxt.common.annotation.ValidateGroup;
import com.dwxt.common.base.BaseResult;
import com.dwxt.common.util.PartyUtil;
import com.dwxt.sport.entity.vo.RunRecordVO;
import com.dwxt.sport.service.RunRecordService;
import com.dwxt.sport.entity.RunRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping("/sport/run")
@RestController
public class RunController {

    @Autowired
    private RunRecordService runRecordService;

    /**
     * showdoc
     *
     * @param stepCount 必选 int 步数
     * @param useTime   必选 long 耗时 秒
     * @param distance  必选 int 距离 米
     * @param calories  必选 int 卡路里
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 体育/健步
     * @title 增加健步运动记录
     * @description 增加健步运动记录
     * @url /sport/run/increaseRunRecord
     */
    @RequestMapping("/increaseRunRecord")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, filedName = "stepCount", notNull = true),
            @ValidateFiled(index = 0, filedName = "useTime", notNull = true),
            @ValidateFiled(index = 0, filedName = "distance", notNull = true),
            @ValidateFiled(index = 0, filedName = "calories", notNull = true),
    })
    public BaseResult increaseRunRecord(RunRecord runRecord) {
        runRecordService.increaseRunRecord(runRecord);
        return BaseResult.ok();
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":{"id":"158502014539731","phone":"15123058497","username":"yanlong","integral":100,"isNameAuthentication":0,"identityCard":"513030199201088419","isHouseHead":1,"headPhotoUrl":"http://127.0.0.1:8052/upload/158502014539731.png","lastSignTime":1585031602000,"createTime":1585048945000,"communityId":1,"todayIntegralMax":100,"communityName":"聚金万佳苑","houseNumber":"10栋32-6"}}
     * @catalog 体育/健步
     * @title 增加积分
     * @description 增加积分
     * @url /sport/run/addIntegral
     */
    @RequestMapping("/addIntegral")
    public BaseResult addIntegral() {
        return runRecordService.addIntegral();
    }

    /**
     * showdoc
     *
     * @param year  必选 int 年
     * @param month 必选 int 月
     * @param day   可选 int 日
     * @return {"status":200,"msg":"SUCCESS","data":{"id":null,"stepCount":144000,"useTime":960000,"distance":40048,"calories":9000,"userId":null,"createTime":null,"updateTime":null,"year":null,"month":null,"day":null}}
     * @catalog 体育/健步
     * @title 查询跑步记录
     * @description 按月或日查询跑步记录
     * @url /sport/run/selectMonthOrDayRunRecord
     */
    @RequestMapping("/selectMonthOrDayRunRecord")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, notNull = true),
            @ValidateFiled(index = 1, notNull = true),
    })
    public BaseResult selectMonthOrDayRunRecord(Integer year, Integer month, Integer day, Integer data) {
        if (data != null && day == null) {
            day = data;
        }
        RunRecord runRecord = runRecordService.selectMonthOrDayRunRecord(PartyUtil.getCurrentUserId(), year, month,
                day);
        return BaseResult.ok(runRecord);
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":{"me":3,"rank":[{"id":null,"stepCount":72000,"useTime":480000,"distance":20024,"calories":48700,"userId":"158502014539730","createTime":null,"updateTime":null,"year":null,"month":null,"day":null,"username":"yanlong","headPhotoUrl":"http://127.0.0.1:8052/upload/158502014539731.png"},{"id":null,"stepCount":72000,"useTime":480000,"distance":20024,"calories":48600,"userId":"158502014539732","createTime":null,"updateTime":null,"year":null,"month":null,"day":null,"username":"yanlong","headPhotoUrl":"http://127.0.0.1:8052/upload/158502014539731.png"},{"id":null,"stepCount":144000,"useTime":960000,"distance":40048,"calories":9000,"userId":"158502014539731","createTime":null,"updateTime":null,"year":null,"month":null,"day":null,"username":"yanlong","headPhotoUrl":"http://127.0.0.1:8052/upload/158502014539731.png"}]}}
     * @catalog 体育/健步
     * @title 查询当月排名
     * @description 查询当月排名
     * @url /sport/run/selectCurrMonthRank
     */
    @RequestMapping("/selectCurrMonthRank")
    public BaseResult selectCurrMonthRank() {
        Map<String, Object> map = runRecordService.selectCurrMonthRank();
        return BaseResult.ok(map);
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":{"me":3,"rank":[{"headPhotoUrl":"http://127.0.0.1:8052/upload/158502014539731.png","calories":48700,"userId":"158502014539730","username":"yanlong"},{"headPhotoUrl":"http://127.0.0.1:8052/upload/158502014539731.png","calories":48600,"userId":"158502014539732","username":"yanlong"},{"headPhotoUrl":"http://127.0.0.1:8052/upload/158502014539731.png","calories":9000,"userId":"158502014539731","username":"yanlong"}]}}
     * @catalog 体育/健步
     * @title 查询全部排名
     * @description 查询全部排名
     * @url /sport/run/selectAllRank
     */
    @RequestMapping("selectAllRank")
    public BaseResult selectAllRank() {
        Map<String, Object> map = runRecordService.selectAllRank();
        return BaseResult.ok(map);
    }

}
